//
//  CustomActionSheet.m
//  Eath
//
//  Created by mao on 11/4/14.
//  Copyright (c) 2014 yuhaya. All rights reserved.
//

#import "CustomActionSheet.h"



@implementation CustomActionSheet

@synthesize view;

@synthesize toolBar;

-(id)initWithHeight:(float)height WithSheetTitle:(NSString*)title

{
    
    self = [super init];
    
    if (self)
        
    {
        
        int theight = height - 40;
        
        int btnnum = theight/50;
        
        for(int i=0; i<btnnum; i++)
            
        {
            
            [self addButtonWithTitle:@""];
            
        }
        
        toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
        
//        toolBar.barStyle = UIBarStyleBlackOpaque;
        
        
        
        UIBarButtonItem *titleButton = [[UIBarButtonItem alloc] initWithTitle:title
                                        
                                                                        style:UIBarButtonItemStylePlain
                                        
                                                                       target:nil
                                        
                                                                       action:nil];
        
        
        
        UIBarButtonItem *rightButton = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStyleDone target:self action:@selector(done)];

        UIBarButtonItem *leftButton  = [[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStyleBordered target:self action:@selector(docancel)];

        UIBarButtonItem *fixedButton  = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
        
        
        
        NSArray *array = [[NSArray alloc] initWithObjects:leftButton,fixedButton,titleButton,fixedButton,rightButton,nil];
        
        [toolBar setItems: array];
        
        
        
        [self addSubview:toolBar];
        
        view = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, height-44)];
        
        view.backgroundColor = [UIColor groupTableViewBackgroundColor];
        
        [self addSubview:view];
        
        UIDatePicker * date = [[UIDatePicker alloc] init];
        self.time = date;
        date.frame = CGRectMake(0, 0, 320, 120);
        date.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1];
        date.datePickerMode = UIDatePickerModeTime;
        [self.view addSubview:date];
        
    }
    
    return self;
    
}

-(void)done

{
    
    [self dismissWithClickedButtonIndex:0 animated:YES];
    
}

-(void)docancel

{
    
    [self dismissWithClickedButtonIndex:0 animated:YES];
    
}


@end